<template>
  <div>
    <!-- <div class="con-banner"> -->
    <v-touch v-on:swipeleft="swiperleft" v-on:swiperight="swiperright">
      <div class="swiper-container3 con-banner">
        <div class="swiper-wrapper con-wrapper">
          <div class="swiper-slide bg-blue"><slot name="s0"></slot></div>
          <div class="swiper-slide bg-blue"><slot name="s1"></slot></div>
          <div class="swiper-slide bg-blue"><slot name="s2"></slot></div>
          <div class="swiper-slide bg-blue"><slot name="s3"></slot></div>
          <div class="swiper-slide bg-blue"><slot name="s4"></slot></div>
          <div class="swiper-slide bg-blue"><slot name="s5"></slot></div>
          <div class="swiper-slide bg-blue"><slot name="s6"></slot></div>
          <div class="swiper-slide bg-blue"><slot name="s7"></slot></div>
          <div class="swiper-slide bg-blue"><slot name="s8"></slot></div>
        </div>
      </div>
    </v-touch>
  </div>
</template>

<script>
import Swiper from "../assets/swiper/dist/js/swiper.min.js";
import "../assets/swiper/dist/css/swiper.min.css";
export default {
  name: "Minbanner",
  props: ["send"],
  data() {
    return {
      // x: 0,
      ifLeft: true,
      ifRight: true,
    };
  },
  methods: {
    swiperleft() {
      if (this.x < 8) {
        this.x++;
        this.ifLeft = true;
        console.log("左划 当前x的值===>", this.x);
        this.$emit("child-click", this.x);
      } else {
        this.x = 8;
        this.ifLeft = false;
        console.log("左划 当前x的值===>", this.x);
        this.$emit("child-click", this.x);
      }
    },
    swiperright() {
      if (this.x > 0) {
        this.x--;
        this.ifRight = true;
        console.log("右滑 当前x的值===>", this.x);
        this.$emit("child-click", this.x);
      } else if (this.x < 1) {
        this.x = 0;
        this.ifRight = false;
        console.log("右滑 当前x的值===>", this.x);
        this.$emit("child-click", this.x);
      }
    },
  },
  created() {
    console.log("重新加载啦");
  },
  watch: {
    // x() {
    //   console.log("数据变化", this.x);
    // },
  },
  mounted() {
    this.x = this.send;
    console.log("index传给子组件的", this.send);
    var mySwiper3 = new Swiper(".swiper-container3", {
      // autoplay: 1000, //可选选项，自动滑动
      initialSlide: this.send,
    });
  },
};
</script>

<style lang="scss" scoped>
.con-banner {
  overflow: auto;
  position: relative;
  top: 46px;
  left: 94px;
  .con-wrapper {
    //   一定要给这个值，tmd搞了一早上草啊
    width: 282px !important;
    .swiper-slide {
      width: 282px !important;
      min-height: 200px;
    }
  }
}
.swiper-slide-active {
  width: 282px !important;
}
.bg-blue {
  // color: skyblue;
  background-color: rgb(255, 255, 255);
}
</style>